<template>

  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import { GetPanelGroup } from '@/api/user'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '400px'
    }
  },
  data() {
    return {
      chart: null,
      list: {
        superior_money: 0,
        build_money: 0,
        internshipM_money: 0,
        subsidy_money: 0
      }
    }
  },
  created() {
    // 获取userid
    this.getUserAdmin()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    // 获取管理员列表
    async getUserAdmin() {
      const formData = await GetPanelGroup()
      this.list.superior_money = parseFloat(formData.superior_money)
      this.list.build_money = parseFloat(formData.build_money)
      this.list.internshipM_money = parseFloat(formData.internshipM_money)
      this.list.subsidy_money = parseFloat(formData.subsidy_money)
      this.initChart()
    },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      const that = this
      this.chart.setOption({
        title: {
          text: '实习申报发放金额', // 图表的标题
          left: 'center', // 标题居中
          top: 'top', // 标题位置在顶部
          textStyle: {
            color: '#333', // 字体颜色设置为黑色
            fontWeight: 'bold' // 加粗字体
          }
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['上级配套奖励金额', '实习交通补贴金额', '基地实习补贴金额', '基地建设奖励金额']
        },
        series: [
          {
            name: '实习补贴申报发放金额',
            type: 'pie',
            roseType: 'radius',
            radius: [25, 95],
            center: ['50%', '48%'],
            data: [
              { value: parseFloat(that.list.superior_money), name: '上级配套奖励金额' },
              { value: parseFloat(that.list.subsidy_money), name: '实习交通补贴金额' },
              { value: parseFloat(that.list.internshipM_money), name: '基地实习补贴金额' },
              { value: parseFloat(that.list.build_money), name: '基地建设奖励金额' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 1500
          }
        ]
      })
    }
  }
}
</script>
